<template>
	<div>
		<div class="h2"> 积分审批节点管理</div>
		<div id="components-form-demo-advanced-search">
			<a-form class="ant-advanced-search-form home-form" :form="form" @submit="handleSearch">
				<a-row :gutter="24">
					<a-col :span="8">
						<a-form-item label="名称"><a-input autocomplete="off" class="field-right" placeholder="请输入名称搜索" v-decorator="[`key`]" /></a-form-item>
					</a-col>
				</a-row>
			</a-form>
		</div>
		<a-button-group size="default" class="option">
			<a-button type="primary" @click="handleSearch">搜索</a-button>
			<a-button @click="handleReset">重置</a-button>
			<a-button type="primary" @click="addList">新增</a-button>
		</a-button-group>
		<div>
			<el-table ref="tableList" :data="data" v-loading="loading" border :max-height="tableHeight" highlight-current-row style="width: 100%;">
				<el-table-column type="index" label="序号" width="60"></el-table-column>
				<el-table-column prop="Name" label="名称" min-width="120"></el-table-column>
				<!-- <el-table-column prop="IsTeacherExam" label="老师审批" min-width="100">
					<template slot-scope="scope">
						<a-tag :color="!scope.row.IsTeacherExam?'red':'green'">{{ scope.row.IsTeacherExam?'是':'否' }}</a-tag>
					</template>
				</el-table-column> -->
				<el-table-column prop="IsAgreeUpdate" label="允许修改" min-width="100">
					<template slot-scope="scope">
						<a-tag :color="!scope.row.IsAgreeUpdate?'red':'green'">{{ scope.row.IsAgreeUpdate?'是':'否' }}</a-tag>
					</template>
				</el-table-column>
				<el-table-column prop="IsAgreeDelete" label="允许删除" min-width="100">
					<template slot-scope="scope">
						<a-tag :color="!scope.row.IsAgreeDelete?'red':'green'">{{ scope.row.IsAgreeDelete?'是':'否' }}</a-tag>
					</template>
				</el-table-column>
				<el-table-column label="操作" width="120" fixed="right">
					<template slot-scope="scope">
						<a-tooltip placement="top">
							<template slot="title">修改</template>
							<i title="修改" class="iconfont icon-editor1" style="color: #1890FF;" @click="modifyList(scope.row, 'modify')"></i>
						</a-tooltip>
						<a-tooltip placement="top">
							<template slot="title">删除</template>
							<i title="删除" class="iconfont icon-delete" style="color: red;" @click="deleteList(scope.row, 1)"></i>
						</a-tooltip>
					</template>
				</el-table-column>
			</el-table>
		</div>
		<add :text="text" v-show="addIf" @closeFun="closeFun"></add>
	</div>
</template>

<script>
import add from './add';
import Func from '@/utils/func';
import moment from 'moment';
import Cache from '@/utils/cache';
import { ManageCreditFlowTypeDoGetList, ManageCreditFlowTypeDoDelete } from '@/api/follow';
const data = [];
export default {
	components: {
		add
	},
	data() {
		return {
			data,
			form: this.$form.createForm(this, {
				name: 'advanced_search'
			}),
			addIf: false,
			text: {},
			loading: false,
			values: {},
			tableHeight: parseFloat(window.innerHeight - 160),
			requestUrl: this.global.requestUrl,
			token: Cache.get('token'),
		};
	},
	computed: {},
	created() {
		this.getList();
	},
	mounted() {},
	methods: {
		moment,
		handleSearch(e) {
			e.preventDefault();
			this.form.validateFields((error, values) => {
				this.values = values;
				this.getList();
			});
		},
		handleReset() {
			this.form.resetFields();
			this.values = {};
			this.getList();
		},
		async getList() {
			this.loading = true;
			let data = {};
			if (this.values) {
				data = this.values;
			}
			let res = await ManageCreditFlowTypeDoGetList(data);
			this.loading = false;
			this.data = res.data.data;
			this.$refs.tableList.bodyWrapper.scrollTop = 0;
		},
		addList() {
			this.text = {};
			this.addIf = !this.addIf;
		},
		modifyList(text) {
			text = { ...text,time: new Date() }
			this.addIf = !this.addIf;
			this.text = text;
		},
		deleteList(text, type) {
			let that = this;
			let content = '';
			switch (type) {
				case 1:
					content = '您确定删除该审批节点吗?';
					break;
				default:
					break;
			}
			this.$confirm({
				title: '提示',
				content: content,
				okText: '确认',
				cancelText: '取消',
				async onOk() {
					let data = {};
					data.id = text.ID;
					let res = await ManageCreditFlowTypeDoDelete(data);
					if (res.data.code == 0) {
						that.getList();
						that.$message.success(res.data.msg);
					} else {
						that.$message.error(res.data.msg);
					}
				}
			});
		},
		closeFun(data) {
			this.addIf = false;
			if (data == 1) {
				this.getList();
			}
		}
	}
};
</script>

<style lang="less" scoped>
.home-form /deep/.ant-form-item {
	display: flex;
	margin-bottom: 10px !important;
}
.home-form /deep/.ant-form-item-label {
	width: 80px;
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
	text-align: right;
}
.home-form /deep/.ant-form-item-control-wrapper {
	flex: 1;
}
.home-form /deep/.ant-calendar-picker {
	width: 100%;
}
/deep/.el-table th.is-leaf {
	background: #fafafa;
}
/deep/.el-table td,
/deep/.el-table th {
	padding: 5px;
}
.option {
	margin-top: 10px;
	margin-bottom: 20px;
	overflow: hidden;
	.ant-btn {
		font-size: 12px;
	}
}
.el-pagination {
	margin-top: 10px;
}
/deep/ .ant-form-item-control-wrapper {
	min-width: 200px;
}
</style>
